package br.com.sge.servicosimp;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.sge.entidades.Disciplina;
import br.com.sge.servicos.DisciplinaServico;
import br.com.sge.util.HibernateUtil;

/**
 *
 * @author Gustavo Rodrigues Torre
 */
public class DisciplinaServicoImp implements DisciplinaServico {

    public void save(Disciplina disciplina) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.save(disciplina);
        t.commit();
    }
    public Disciplina getDisciplina(long id) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        return (Disciplina) session.load(Disciplina.class, id);
    }
    public List<Disciplina> list() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        List lista = session.createQuery("from Disciplina").list();
        t.commit();
        return lista;
    }
    
    public void remove(Disciplina disciplina) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.delete(disciplina);
        t.commit();
    }
    public void update(Disciplina disciplina) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction t = session.beginTransaction();
        session.update(disciplina);
        t.commit();
    }
}
